package com.xian.cloud.core.impl;

import com.codingapi.tx.annotation.TxTransaction;
import com.xian.cloud.core.LogCoreService;
import com.xian.cloud.entity.LogEntity;
import com.xian.cloud.entity.UserEntity;
import com.xian.cloud.face.LogService;
import com.xian.cloud.fegin.UserRpcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author: xlr
 * @Date: Created in 下午6:29 2018/11/11
 */
@Service
public class LogCoreServiceImpl implements LogCoreService {

    @Autowired
    private LogService logService;

    @Autowired
    private UserRpcService userRpcService;

    /**
     * 保存日志
     *
     * @param logEntity
     * @return
     */
    @Override
    @TxTransaction(isStart = true)
    @Transactional
    public Boolean save(LogEntity logEntity) {
        logService.insert( logEntity );
        UserEntity user = new UserEntity();
        user.setEmail( "402701653@qq.com" );
        user.setPassWord( "123456" );
        user.setUserName( "liru" );
        Boolean flag = userRpcService.saveUser( user );
        if(!flag){
            throw new RuntimeException(  );
        }
        return true;
    }

    /**
     * 根据Id 查询实体类
     *
     * @param id
     * @return
     */
    @Override
    public LogEntity findById(Long id) {
        return logService.selectById( id );
    }
}
